/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jay9downloader;

import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Jonas
 */
public class VideoDetailsModel extends AbstractTableModel implements ListSelectionListener {

    private JList listData;

    private ArrayList<String> detailsLabels = new ArrayList<String>();
    private ArrayList<String> detailsValues = new ArrayList<String>();

    public VideoDetailsModel(JList jlist) {
        super();
        this.listData = jlist;

        listData.addListSelectionListener(this);
        detailsLabels.add(0, "Video name: ");
        detailsLabels.add(1, "URL: ");
        detailsLabels.add(2, "Duration: ");
        detailsLabels.add(3, "Resolution: ");
        detailsLabels.add(4, "Date: ");

        detailsValues.add(0, "");
        detailsValues.add(1, "");
        detailsValues.add(2, "");
        detailsValues.add(3, "");
        detailsValues.add(4, "");

    }

    public int getRowCount() {
        return detailsLabels.size();

    }

    public int getColumnCount() {
        return 2;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if(columnIndex == 0)
            return detailsLabels.get(rowIndex);
        else
            return detailsValues.get(rowIndex);
    }

    public void valueChanged(ListSelectionEvent e) {
        if(!((JList)e.getSource()).isSelectionEmpty()) {
            detailsValues.set(0, ((Video)((JList)e.getSource()).getSelectedValue()).getTitle());
            detailsValues.set(1, ((Video)((JList)e.getSource()).getSelectedValue()).getUrl());
            detailsValues.set(2, ((Video)((JList)e.getSource()).getSelectedValue()).getDurationAsString());
            detailsValues.set(3, ((Video)((JList)e.getSource()).getSelectedValue()).getWidth() + "x" + ((Video)((JList)e.getSource()).getSelectedValue()).getHeight());
            detailsValues.set(4, ((Video)((JList)e.getSource()).getSelectedValue()).getTimestampAsDateFormattedString());
            this.fireTableDataChanged();
        }
    }

}
